package com.ruoyi.doorcontrol.start;

import com.ruoyi.doorcontrol.sdk.HCNetSDK;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @Author: meng
 * @Date: 2021-06-22 16:54
 */
@Slf4j
@Component
public class MyApplicationRunner implements ApplicationRunner {






    //门禁端
   /* @Override
    public void run(ApplicationArguments args) throws Exception {
        HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

        log.info("===============");
        new Thread(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            boolean b = hCNetSDK.NET_DVR_Init();

            hCNetSDK.NET_DVR_SetConnectTime(10, 1);
            hCNetSDK.NET_DVR_SetReconnect(100, true);
            if (!b) {
                log.error("=================== SDK init fail ===================");
            } else {
                log.info("============== SDK init success ====================");

                List<ThDoorControl> controlList = thDoorControlService.selectThDoorControlList(new ThDoorControl());
                for (ThDoorControl thDoorControl : controlList) {
                    AjaxResult login_ajaxResult = loginService.login3(thDoorControl.getId());
                    if ("200".equals(login_ajaxResult.get("code").toString())) {
                        System.out.println(thDoorControl.getNotes() + "登录成功！");
                        AjaxResult bufang_ajaxResult = hkEventService.startSubscribe(thDoorControl.getId());
                        if ("200".equals(bufang_ajaxResult.get("code").toString())) {
                            System.out.println(thDoorControl.getNotes() + "布防成功！");
                        }
                    } else {
                        System.out.println(thDoorControl.getNotes() + "登录失败！");
                    }
                }
            }
        }).start();
    }*/

    //服务端
    @Override
    public void run(ApplicationArguments args) throws Exception {
        HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
        hCNetSDK.NET_DVR_Init();
    }
}
